<!-- 会签信息 -->
<template>
  <TCollapse v-if="+showType" title="会签信息">
    <iframe :src="taskDetailsUrl" scrolling="no" width="100%" :height="taskHeight" frameborder="0" />
  </TCollapse>
  <iframe v-else :src="taskDetailsUrl" scrolling="no" width="100%" :height="taskHeight" frameborder="0" />
</template>
<script>

import TCollapse from '@/components/basic/TCollapse.vue'

export default {
  name: 'JnTaskDetail',
  components: { TCollapse },
  props: {
    processInstId: {
      type: [Number, String],
      default: 0
    },
    showType: {
        type: String,
        default: '1'
    }
  },
  inject: ['prjDetail', 'workDetail','countersignDetail'],
  data() {
    return {
      taskHeight: ''
    }
  },
  computed: {
    newPrjDetail() {
      return this.prjDetail()
    },
    newWorkDetail() {
      return this.workDetail()
    },
    newCountersignDetail(){
      return this.countersignDetail()
    },
    taskDetailsUrl() {
      const params = {
        prjId: this.newPrjDetail.prjId,
        nodeId:　this.newWorkDetail.bizObject.nodeCode,
        templateId:　this.newWorkDetail.processDefName,
        prjStage: this.newWorkDetail.bizObject.wfStage,
        roleCode: this.newCountersignDetail.hqRoles,
        nodeName: this.newWorkDetail.activityInstName,
        procInstId: this.newWorkDetail.processInstID,
        orgId: this.newPrjDetail.orgId,
        parentBizSeq: this.newWorkDetail.bizObject.bizSeq,
        pendingType: this.newWorkDetail.bizObject.pendingType
      }
      console.log('会签', this.joinParams(params))
      return `${process.env.VUE_APP_JUNNAN_IFRAME_URL}countersign/countersignPersonInfo${this.joinParams(params)}`
    }
  },
  async created() {
    window.addEventListener('message', (event) => {
      const base_url = ''
      if (event.origin === base_url) {
        return
      }
      if (event.data.type === 'countersignHeight') {
        console.log('项目会签信息', event.data)
        this.taskHeight = event.data.height
      }
    })
  },
  methods: {
    joinParams(obj) {
      let result = ''
      for (const objKey in obj) {
        const prefix = result ? '&' : '?'
        result += `${prefix}${objKey}=${obj[objKey]}`
      }
      return result
    }
  }
}
</script>

<style scoped lang='scss'>
</style>
